﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.SuperGrid;

namespace KEEPER_BRR_13dotNET.Presentation.Controls
{
    public class GridMenuBar : DevComponents.DotNetBar.Bar
    {
        private ButtonItem[] allItem;

        private SuperGridControl _Grid;
        public SuperGridControl Grid
        {
            get
            {
                return _Grid;
            }
            set
            {
                if (_Grid != null)
                    DetachGrid();

                _Grid = value;
                if (_Grid != null)
                    AttackGrid();
            }
        }

        public GridMenuBar()
            : base("Là như thế này sao")
        {
            this.SuspendLayout();
            BeginInit();
            allItem = new ButtonItem[4];
            allItem[0] = new ButtonItem("biRefresh");
            allItem[0].ButtonStyle = eButtonStyle.ImageAndText;
            allItem[0].Text = "Làm mới";

            allItem[1] = new ButtonItem("biAdd");
            allItem[1].ButtonStyle = eButtonStyle.ImageAndText;
            allItem[1].Text = "Thêm mới";

            allItem[2] = new ButtonItem("biEdit");
            allItem[2].ButtonStyle = eButtonStyle.ImageAndText;
            allItem[2].Text = "Sửa";

            allItem[3] = new ButtonItem("biDelete");
            allItem[3].ButtonStyle = eButtonStyle.ImageAndText;
            allItem[3].Text = "Xóa";
            Items.AddRange(allItem);
            EndInit();
            ResumeLayout();
        }

        private void DetachGrid()
        {
            _Grid.RowClick -= _Grid_RowClick;
            _Grid.SelectionChanged -= _Grid_SelectionChanged;
        }

        void _Grid_SelectionChanged(object sender, GridEventArgs e)
        {

        }

        void _Grid_RowClick(object sender, GridRowClickEventArgs e)
        {

        }
        private void AttackGrid()
        {
            _Grid.RowClick += new EventHandler<GridRowClickEventArgs>(_Grid_RowClick);
            _Grid.SelectionChanged += new EventHandler<GridEventArgs>(_Grid_SelectionChanged);
        }
    }
}
